﻿/*-------------------------------------------------------------------------
* 命名空间: SiliconSelect.Common/ExceptionHelper
* 类       名: ExceptionHelper
* 功      能:  TD
* 时      间:  2023/6/28 13:54:50
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace SiliconSelect.Common
{
    public class ExceptionHelper
    {
        /// <summary>
        /// 为异常信息添加文件名以及函数名.
        /// </summary>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static string GetFullException(Exception ex, MethodBase method)
        {
            //MethodBase? method = ex.TargetSite;
            //string? fileName = ex.GetType().FullName;
            Type? type = method.DeclaringType;
            string? fileName = type?.FullName;
            return ex.Message + $"\n异常位置, 文件名:  {fileName ?? ""}  函数名:  {method?.Name ?? ""}()";
        }
    }
}
